//
//  VisitorTableViewController.swift
//  Weibo
//
//  Created by apple on 15/12/6.
//  Copyright © 2015年 idcast. All rights reserved.
//

import UIKit

class VisitorTableViewController: UITableViewController {

    
    //用户登陆标记
//    private var userLogon = true
    
    private var userLogon = UserAccountViewModel.sharedUserAccount.userLogon

    
    //访客试图
    var visitorView: VisitorView?
    
    override func loadView() {
//        print("nihao")
//        super.loadView()
        userLogon ? super.loadView() : setupVisitorView()
     
    }
    
    private func setupVisitorView() {
    
        //替换试图
        visitorView = VisitorView()
        visitorView?.delegate = self
        view = visitorView

       navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "visitorViewDidRegister")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "visitorViewDidLogin")
        navigationItem.leftBarButtonItem?.tintColor = UIColor.orangeColor()
        navigationItem.rightBarButtonItem?.tintColor = UIColor.orangeColor()
    }
}
// MARK: - 访客视图监听方法
extension VisitorTableViewController: VisitorViewDelegate {
    
    func visitorViewDidRegister() {
        print("注册")
    }
    
    func visitorViewDidLogin() {
        let nav = UINavigationController(rootViewController: OAuthViewController())
        presentViewController(nav, animated: true, completion: nil)
        
        print("登录")
    }
    
}
